package org.graduation.model.dtos.project;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.graduation.model.common.project.Task;
import org.graduation.model.common.project.TaskAndUserTable;
import org.graduation.model.common.user.User;
import org.graduation.model.dtos.DTO;

import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreateTaskDTO implements DTO {
    private String name;
    private String description;
    private Long phaseId;
    private Long projectId;
    private Date beginTime;
    private Date endTime;

    private List<User> users;

    public Task getTask() {
        Task task = new Task();
        task.setName(name);
        task.setDescription(description);
        task.setPId(projectId);
        task.setPhaseId(phaseId);
        task.setBeginTime(beginTime);
        task.setEndTime(endTime);
        return task;
    }

    public List<TaskAndUserTable> getTaskAndUserTables(Long taskId) {
        return users.stream().map(user -> {
            TaskAndUserTable taskAndUserTable = new TaskAndUserTable();
            taskAndUserTable.setUid(user.getUid());
            taskAndUserTable.setTaskId(taskId);
            return taskAndUserTable;
        }).collect(java.util.stream.Collectors.toList());
    }
}
